﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;

namespace StevensReceipts.Domain
{
    public class ChartofAccount :  IEntity
    {
        public ChartofAccount()
        {
            Created = DateTime.Now;
            IsSystemAccount = false;
            IsDefaultAccount = false;
            Balance = 0;
        }

        //unique identitier
        public int Id { get; set; }

        public int AccountTypeId { get; set; }

        //the type of the chart of accounts
        [ForeignKey("AccountTypeId")]
        [JsonIgnore]
        public virtual ChartofAccountAccountType AccountType { get; set; }

        //the system account is the ones loaded when a new account is created
        //system account can't be deleted/archived
        public bool IsSystemAccount { get; set; }

        public bool IsDefaultAccount { get; set; }
        //a unique code/number for this account
        public int Code { get; set; }
        //a short title for this account
        [StringLength(150)]
        public string Name { get; set; }
        //description how this account should be used
        [StringLength(255)]
        public string Description { get; set; }

        public int DefaultTaxRateId { get; set; }

        //the default tax rate for this account
        [ForeignKey("DefaultTaxRateId")]
        [JsonIgnore]
        public virtual TaxRate TaxRate { get; set; }

        //the default tax return percentage 
        public double TaxReturnPercent { get; set; }

        //the balance of this account for the current period
        [DataType(DataType.Currency)]
        public double Balance { get; set; }

        public int BusinessId { get; set; }
        [ForeignKey("BusinessId")]
        [JsonIgnore]
        public virtual Business Business { get; set; }


        public DateTime? Created { get; set; }

        public DateTime? Modified { get; set; }
    }
}